import os
import sys
import time
from sync_manager import SyncManager
from database import db_manager

print("脚本开始执行")
print(f"当前工作目录: {os.getcwd()}")

# 初始化数据库管理器
db_path = 'sync_cloud.db'
if not os.path.exists(db_path):
    db_path = os.path.join('db', 'sync.db')
    
print(f"使用数据库路径: {db_path}")
if not os.path.exists(db_path):
    print(f"错误: 数据库文件 {db_path} 不存在")
    sys.exit(1)

db_manager.init_app(db_path)

# 创建同步管理器实例
sync_manager = SyncManager()

# 检查同步管理器中的处理器
print("\n同步管理器中的处理器:")
for sync_dir_id, handler in sync_manager.handlers.items():
    print(f"处理器ID: {sync_dir_id}")
    if handler and handler.syncer:
        syncer = handler.syncer
        sync_info = syncer.get_sync_info()
        print(f"  本地路径: {sync_info['local_path']}")
        print(f"  FTP主机: {sync_info['ftp_host']}")
        print(f"  FTP用户: {sync_info['ftp_user']}")
        print(f"  FTP路径: {sync_info['ftp_path']}")
    else:
        print("  同步器未初始化")
    print("-" * 30)

# 检查数据库中的同步目录
print("\n数据库中的同步目录:")
with db_manager.get_connection() as db:
    rows = db.execute('SELECT id, local_path, ftp_host, ftp_user, ftp_path FROM sync_dirs').fetchall()
    for row in rows:
        print(f"ID: {row['id']}")
        print(f"本地路径: {row['local_path']}")
        print(f"FTP主机: {row['ftp_host']}")
        print(f"FTP用户: {row['ftp_user']}")
        print(f"FTP路径: {row['ftp_path']}")
        print("-" * 30)

print("脚本执行完毕") 